<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Contract-add</title>
    <!-- 引入layui 样式-->
    <link rel="stylesheet" href="../../static/css/style.css"/>
    <link rel="stylesheet" href="../../static/layer/css/layui.css"/>
    <link rel="stylesheet" href="../../static/css/font-awesome.min.css">
    <link rel="stylesheet" href="../../static/ucss/contract/loan.css"/>
    <style>
        .layui-form{
            margin-left: 7%;
            margin-top: 20px;
        }
        .layui-form-label{
            width:200px!important;
        }

        .class_company_type_two{
            display: none;
        }
        .layui-form-item{
            margin-left: -28px;
        }
    </style>
</head>

<body>
<form class="layui-form" action=""  id="Shareholder_ID">

    <input type="hidden" name="ID" ID="ID" >
    <div class="layui-form-item">
        <label class="layui-form-label">股东类型</label>
        <div class="layui-input-block">
            <input type="radio" name="TYPE" value="1" title="自然人" checked  lay-filter="radio_type">
            <input type="radio" name="TYPE" value="2" title="企业法人" lay-filter="radio_type" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label class_sh_name">姓名</label>
        <div class="layui-input-inline">
            <input type="text" name="SH_NAME"   id="SH_NAME" lay-verify="required" placeholder="请输入姓名" maxlength="20"  autocomplete="off" class="layui-input">
        </div>

    </div>




    <div class="layui-form-item class_company_type_one">
        <label class="layui-form-label">国籍</label>
        <div class="layui-input-inline">
            <input type="text" name="NATIONALITY"   placeholder="请输入国籍"  maxlength="10"  autocomplete="off" class="layui-input">
        </div>

    </div>


   <!-- <div class="layui-form-item class_company_type_two">
        <label class="layui-form-label">公司名称</label>
        <div class="layui-input-inline">
            <input type="text" name="SH_NAME"   placeholder="请输入公司名称" autocomplete="off" class="layui-input">
        </div>

    </div>-->


    <div class="layui-form-item  class_company_type_two">
        <label class="layui-form-label">公司类型</label>
        <div class="layui-input-inline">
            <select name="COMPANY_TYPE" >
                <option value="1">国有企业</option>
                <option value="2">私营企业</option>
                <option value="3">外商投资企业</option>
                <option value="4">其他</option>
            </select>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">投资金额: 认缴(万元)</label>
        <div class="layui-input-inline">
            <input type="text" name="CONFIS"   lay-verify="number"  placeholder="请输入金额" autocomplete="off" maxlength="10"  class="layui-input">
        </div>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">实缴(万元 )</label>
        <div class="layui-input-inline">
            <input type="text" name="REAL_PAYMENT"    lay-verify="number"   placeholder="请输入金额"  maxlength="10"  autocomplete="off" class="layui-input">
        </div>

    </div>

    <div class="layui-form-item ">
        <label class="layui-form-label class_card_no class_card_val">身份证号码</label>
        <div class="layui-input-inline">
            <input type="text" name="CARD_NO"   id="CARD_NO"   lay-verify="card_no"   maxlength="18" placeholder="请输入身份证号码" autocomplete="off" class="layui-input">
        </div>
    </div>
<!--

    <div class="layui-form-item ">
        <label class="layui-form-label">统一社会信用代码</label>
        <div class="layui-input-inline">
            <input type="text" name="CARD_NO"   placeholder="请输入统一社会信用代码" autocomplete="off" class="layui-input">
        </div>
    </div>
-->

    <div class="layui-form-item">
        <label class="layui-form-label">持股比例(%)</label>
        <div class="layui-input-inline">
            <input type="text" name="CGBI"   placeholder="请输入持股比例"  lay-verify="required"  maxlength="10"  autocomplete="off" class="layui-input">
        </div>

    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">认缴时间</label>
        <div class="layui-input-inline">
            <input type="text" name="CONFIS_DATE"    ID="CONFIS_DATE"  lay-verify="required"   placeholder="请输入认缴时间" autocomplete="off" class="layui-input">
        </div>

    </div>



    <div class="layui-form-item"  style="padding-top: 20px;">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo"   style="margin-left: 85px;" type="button">提交</button>
            <button type="button" class="layui-btn layui-btn-primary" onclick="cancel()">返回</button>
        </div>
    </div>
</form>

</body>
<script type="text/javascript" src="../../static/layer/layui.js"></script>
<script type="text/javascript" src="../../static/js/common/dateUtils.js"></script>
<script type="text/javascript" src="../../static/js/common/typeUtils.js"></script>
<script type="text/javascript" src="../../static/js/common/queryUtils.js"></script>
<script type="text/javascript" src="../../static/js/common/utils.js"></script>
<script>
    //Demo
    var $, element, layer, laydate, form,table;
    var UUID = QueryUtils.GetQueryString("UUID");//合同id

    var ID = QueryUtils.GetQueryString("ID");//股东ID
    layui.use(['jquery', 'element', 'layer', 'laydate', 'form', 'upload','table'], function () {
        // 加载元素控件
        $ = layui.jquery, element = layui.element, layer = layui.layer, laydate = layui.laydate,table = layui.table, form = layui.form;

        laydate.render({
            elem: '#CONFIS_DATE'
        });

        //是否回显
        isShow(ID);

        //自定义验证规则
        form.verify({

            number: function (value) {
                debugger

                var reg = /^\d+(\.\d+)?$/;
                if (value=="") {
                    return '必填项不能为空';
                }
                if (!reg.test(value)) {
                    return '你输入的字符不是数字';
                }


            },

                card_no: function (value) {
                    debugger


                        if (value == "") {
                            return '必填项不能为空';
                        }
                        if (value.length!=18) {

                            if ($(".class_card_val").html() == "身份证号码") {
                                return '请输入正确的身份证号码';
                            } else {
                                return '请输入正确的统一社会信用代码';
                            }

                        }



                },


    })


        //监听提交
        form.on('submit(formDemo)', function(data){


            var dataList = {};
            dataList=data.field;
            dataList.LOAN_ID=UUID;


            if(dataList.TYPE==1){
                dataList.COMPANY_TYPE="0";
            }
            layer.msg('确认新增股东吗', {
                time: 0
                , btn: ['确定', '取消']
                , shade: 0.3
                , yes: function (index) {
                    layer.close(index); // 关闭当前提示框
                    var i = parent.layer.getFrameIndex(window.name);
                    $.ajax({
                        url: "/LoanQTController/saveShareholder",
                        data: dataList,
                        dataType: "json",
                        type: "post",
                        async: false,
                        success: function (res) {
                            if (res.errcode === "0") {
                                debugger
                             //   window.parent.frames[0].test();
                                parent.layer.close(i);  // 关闭新建合同页面
                                parent.layer.msg("保存成功");   // 父页面弹出保存成功
                            } else if (res.errcode === "1") {
                                layer.msg("保存失败");
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            layer.msg("保存失败");
                            console.error(XMLHttpRequest.status);
                            console.error(XMLHttpRequest.readyState);
                            console.error(textStatus);
                        }
                    });
                }
            });
        });

        form.on('radio(radio_type)', function(data){
            radioType(data.value);
        });
    });



//是否回显
    function  isShow(ID){
        debugger
        if(ID!=null && ID!="" && typeof(ID)!="undefined" ){
            var sendData={};
            sendData.ID=ID;
            $.ajax({
                url: "/LoanQTController/findByIdShare",
                data: sendData,
                dataType: "json",
                type: "post",
                async: false,
                success: function (res) {

                    if (res.errcode === "0") {
                        radioType(res.data.TYPE);
                        utils.setFormData("#Shareholder_ID",res.data);
                        form.render();
                    } else if (res.errcode === "1") {
                        layer.msg("查询失败");

                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.msg("查询失败");
                    console.error(XMLHttpRequest.status);
                    console.error(XMLHttpRequest.readyState);
                    console.error(textStatus);
                }
            });

        }

    }
    // 取消
   function cancel() {
        // 当你在iframe页面关闭自身时
        var index = parent.layer.getFrameIndex(window.name); // 先得到当前iframe层的索引
        parent.layer.close(index); // 再执行关闭
    }

    function  radioType(value){
        if(value==1){

            $(".class_card_no").html("身份证号码");
            $("#CARD_NO").attr("placeholder","请输入身份证号码");
            $(".class_sh_name").html("姓名");
            $("#SH_NAME").attr("placeholder","请输入姓名");



            $(".class_company_type_two").hide();
            $(".class_company_type_one").show();
        }else{
            $(".class_card_no").html("统一社会信用代码");
            $("#CARD_NO").attr("placeholder","请输入统一社会信用代码");

            $(".class_sh_name").html("公司名称");
            $("#SH_NAME").attr("placeholder","请输入公司名称");
            $(".class_company_type_two").show();
            $(".class_company_type_one").hide();
        }

    }

</script>
</html>